package com.fk.service;

import java.util.ArrayList;
import java.util.List;

import com.fk.bean.Question;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class DBService {
	
	SQLiteDatabase db;
	
	public DBService(){
		db = SQLiteDatabase.openDatabase("/data/data/com.fk.regimen/Questions.db", null, SQLiteDatabase.OPEN_READWRITE);
	}
	
	
	//编写一个方法，用来获取数据库中的问题
	public List<Question> getQuestions(){
		List<Question> list = new ArrayList<Question>();
		String sql = "select * from question";
		Cursor cursor = db.rawQuery(sql, null);
		if(cursor.getCount() > 0){
			cursor.moveToFirst();
			int count = cursor.getCount();
			for(int i=0;i<count;i++){
				cursor.moveToPosition(i);
				Question question = new Question();
				question.qdescription = cursor.getString(cursor.getColumnIndex("qdescription"));
				question.answerA = cursor.getString(cursor.getColumnIndex("answerA"));
				question.answerB = cursor.getString(cursor.getColumnIndex("answerB"));
				question.answerC = cursor.getString(cursor.getColumnIndex("answerC"));
				question.answerD = cursor.getString(cursor.getColumnIndex("answerD"));
				question.answerE = cursor.getString(cursor.getColumnIndex("answerE"));
				question.selectedAnswer = "";
				list.add(question);
				
			}
			
		}
		
		return list;
		
	}
	

}
